<template>
	<view class="bac">

		<view class="shop">
			<view class="ima" v-for="(item,index) in getList" :key='index' @tap="buys(item.id,item.price)">
				<image :src="item.image" mode="widthFix"></image>
				<view class="characters">
					<text class="titile ">{{ item.title }} </text>
					<view class="price">
						<text class="pricered">${{ item.price }}</text>
						<!-- <text class="number">库存{{ item.num }}件</text> -->
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

				getList: []
			}
		},
		created() {
			this.getShOpp();
		},
		//监听上拉刷新
		onReachBottom() {},
		methods: {
			getShOpp() {
				this.$ajax(
					this.apiList.Shopping, {},
				).then(res => {
					this.getList = res.data
				})
			},
			// 购买
			buys(id, price) {
				uni.showModal({
					content: '是否购买！！！！',
					success: res => {
						if (res.confirm) {
							this.$ajax(
								this.apiList.buys, {
									id: id,
									num: 1,
									price: price,
									userId: uni.getStorageSync('userinfo').userId
								},
							).then(res => {
								if (res.resultCode == 1) {
									this.$sToast('购买成功!')
								} else {
									this.$sToast('购买失败!')
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		// padding: 20upx ;
		// background:#eee;
		box-sizing: border-box;
		overflow-y: scroll;

	}

	.bac {
		padding: 0upx 20upx;
		// background:#eee;
	}

	.casslify {
		background-color: #fff;
		width: 100%;
		display: flex;
		height: auto;
		box-sizing: border-box;
		border-radius: 10upx 10upx 0 0;
		padding: 20upx;

		.lei {
			display: flex;
			align-items: center;
			justify-content: center;
			flex: 1;

			text {
				font-size: 14px;
			}

			image {
				width: 20px;
				margin-left: 10upx;
			}
		}
	}

	.shop {
		width: 100%;
		height: auto;
		box-sizing: border-box;
		// display: flex;
		// justify-content: space-between;
		// flex-wrap: wrap;
		padding-top: 15upx;
		// margin: 0 auto;
		padding-right: 10upx;
		width: 100%;
		column-count: 2;
		column-width: 100%;
		column-gap: 25upx;

		.ima {
			width: 100%;
			padding: 5upx;
			break-inside: avoid;
			background-color: rgb(14,17,69);
			margin-bottom: 15upx;
			border-radius: 10upx 10upx 0 0;

			image {
				width: 100%;
			}

			.characters {
				width: 100%;
				.titile {
					display: inline-block;
					width: 100%;
					padding: 0 10upx;
					box-sizing: border-box;
					font-size: 14px;
					color: #fff;
					@include text-ellipsis-two();
				}
				.price {
					display: flex;
					flex-direction: column;

					.pricered {
						font-size: 16px;
						color: red;
						margin-bottom: 10upx;
						padding: 0 10upx;
					}

					.number {
						font-size: 10px;
						color: #e0e0e0;
						padding: 0 10upx;
					}
				}
			}
		}
	}
</style>
